<template>
  <div id="nav">
    <!-- 第一种路由跳转 -->
    <router-link to="/">Home</router-link> |
    <!-- <router-link to="/about">About</router-link> -->

    <!-- 第二种路由跳转 -->
    <button @click="aboutClick">关于</button>

    <!-- 第三种路由跳转 -->
    <!-- <router-link :to="'/user/'+userId">用户</router-link> -->
    <button @click="userClick">用户</button>

    <!-- 第四种路由跳转 -->
    <!-- 注意：如果提供了 path，params 会被忽略 -->
    <!-- 命名形式：<router-link :to="{name:'/profile',query:{name:'why',age:18,height:188}}">档案</router-link> -->
    <!-- 路径形式：<router-link :to="{path:'/profile',query:{name:'why',age:18,height:188}}">档案</router-link> -->
    <button @click="profileClick">档案</button>

    <keep-alive>
      <router-view />
    </keep-alive>
    
  </div>
</template>

<script>
export default {
  data() {
    return {
      userId:'lisi'
    };
  },
  methods: {
    //第二种路由跳转
    aboutClick() {
      this.$router.push('/about');
    },
    //第三种路由跳转：params类型
    userClick(){
      console.log("san");
      this.$router.push('/user/' + this.userId)
    },
    //第四种路由跳转：query类型
    profileClick(){
      console.log("si");
      this.$router.push({
        path:'/profile',
        query:{
          name:'why',
          age:18,
          height:188
        }
      })
    }
  },
  //监听
  watch: {},
  components: {},
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>
